<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Dao;

use App\Kernel\Traits\DaoTrait;
use App\Model\PlatformOrder;

/**
 * class
 *
 * @author 张昊(2396675557@qq.com)
 * @package App\Dao
 */
class PlatformOrderDao extends Dao
{

    /**
     * 订单状态：待支付
     *
     * @var int
     */
    const STATUS_UNPAID = 0;

    /**
     * 订单状态：已支付
     *
     * @var int
     */
    const STATUS_PAID = 1;

    use DaoTrait;

    public function model(): string
    {
        return PlatformOrder::class;
    }

    /**
     * 通过 id 获取 sku
     *
     * @param array $map
     * @param bool $abnormal
     * @return mixed
     */
    public function first(array $map, bool $abnormal = true)
    {
        $first = PlatformOrder::query()->where(function ($query) use ($map) {
            return queryWhere($query, $map);
        })->first();

        if (!$first && $abnormal === true) {
            $this->error('CART.SKU_NOT_EXIST');
        }

        return $first;
    }
}